package cn.iocoder.yudao.hires.controller.admin;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;


import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import  cn.iocoder.yudao.hires.vo.*;
import cn.iocoder.yudao.hires.entity.ResumeIntentionDO;
import cn.iocoder.yudao.hires.service.ResumeIntentionService;

@Tag(name = "管理后台 - 简历-求职意向")
@RestController
@RequestMapping("/resume/intention")
@Validated
public class ResumeIntentionController {

    @Resource
    private ResumeIntentionService intentionService;

    @PostMapping("/create")
    @Operation(summary = "创建简历-求职意向")
    //@PreAuthorize("@ss.hasPermission('resume:intention:create')")
    public CommonResult<Integer> createIntention(@Valid @RequestBody ResumeIntentionSaveReqVO createReqVO) {
        return success(intentionService.createIntention(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新简历-求职意向")
    //@PreAuthorize("@ss.hasPermission('resume:intention:update')")
    public CommonResult<Boolean> updateIntention(@Valid @RequestBody ResumeIntentionSaveReqVO updateReqVO) {
        intentionService.updateIntention(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除简历-求职意向")
    @Parameter(name = "id", description = "编号", required = true)
    //@PreAuthorize("@ss.hasPermission('resume:intention:delete')")
    public CommonResult<Boolean> deleteIntention(@RequestParam("id") Integer id) {
        intentionService.deleteIntention(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得简历-求职意向")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    //@PreAuthorize("@ss.hasPermission('resume:intention:query')")
    public CommonResult<ResumeIntentionRespVO> getIntention(@RequestParam("id") Integer id) {
        ResumeIntentionDO intention = intentionService.getIntention(id);
        return success(BeanUtils.toBean(intention, ResumeIntentionRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得简历-求职意向分页")
    //@PreAuthorize("@ss.hasPermission('resume:intention:query')")
    public CommonResult<PageResult<ResumeIntentionRespVO>> getIntentionPage(@Valid ResumeIntentionPageReqVO pageReqVO) {
        PageResult<ResumeIntentionDO> pageResult = intentionService.getIntentionPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ResumeIntentionRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出简历-求职意向 Excel")
    //@PreAuthorize("@ss.hasPermission('resume:intention:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportIntentionExcel(@Valid ResumeIntentionPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ResumeIntentionDO> list = intentionService.getIntentionPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "简历-求职意向.xls", "数据", ResumeIntentionRespVO.class,
                        BeanUtils.toBean(list, ResumeIntentionRespVO.class));
    }

}